﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using DataBusiness;
using Common;
using DevExpress.XtraEditors.Controls;

namespace UI.BasicData
{
    public partial class frmDemo  : DevExpress.XtraEditors.XtraForm
    {
        public frmDemo()
        {
            InitializeComponent();
        }

        //加载窗体
        private void frmDemo_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("id", typeof(string)));
            dt.Columns.Add(new DataColumn("text", typeof(string)));
            dt.Rows.Add(new Object[] { "0", "系统管理员" });
            dt.Rows.Add(new Object[] { "1", "设计人员" });
            dt.Rows.Add(new Object[] { "2", "查看人员" });

            cmbType.EditValue = "id";
            cmbType.Properties.DisplayMember = "text";
            cmbType.Properties.ValueMember = "id";
            cmbType.Properties.DataSource = dt;
            cmbType.Properties.PopulateColumns();
            cmbType.Properties.Columns[0].Visible = false;
            cmbType.Properties.Columns[0].Caption = "类型id";
            cmbType.Properties.Columns[1].Caption = "用户类型";
            cmbType.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; //默认不可编辑
            cmbType.ItemIndex = 0; //默认显示第一行

            BindData();
        }

        //查询
        private void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        //绑定数据列表
        private void BindData()
        {
            dGrid.DataSource = UserBLL.GetUsers(txtName.Text, cmbType.EditValue.ToString()).Tables[0];
        }

        //导出列表数据
        private void btnExport_Click(object sender, EventArgs e)
        {
            AppMethod.ExportDataToExcel(gridView1, dGrid);
        }
    }
}
